﻿<%@ Page Language="C#" MasterPageFile="~/tab/tab2010.master" AutoEventWireup="true"
    CodeFile="fundfav.aspx.cs" Inherits="tab_fundfav" Title="Untitled Page" %>

<%@ Register Src="fundopenleft.ascx" TagName="fundopenleft" TagPrefix="uc1" %>
<%@ Register Src="toptree.ascx" TagName="toptree" TagPrefix="uc2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="toptree" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="title" runat="Server">
    <script type="text/javascript">
        $(document).ready(function () {

            loading();
            if (top.location.href.indexOf("?") > 0) {
                querycode = getRequestCode();
                codeIsRight(querycode);
            } else {
                initFavList();
            }
        });
        function loading() {
            //removeRows();
            var str = "<tr height=\"200\"><td align=\"center\" valign=\"top\" colspan=\"10\" style=\"background-color: White\"><br /><br /><img src=\"http://i.ssimg.cn/images/fund2010/loading.gif\"/></td></tr>";

            $("#datatable").append(str);
        }

        function getRequestCode() {
            var querycode = top.location.href;
            if (querycode.indexOf("?") > 0) {
                querycode = querycode.substr(querycode.indexOf("?") + 1);
                if (querycode.indexOf("=" > 0)) {
                    querycode = querycode.substr(querycode.indexOf("=") + 1);
                }
                return querycode;
            }
        }

        function initFavList() {
            var codes = getcookie("fundfavlist");
            var Rand = Math.random();
            //alert(codes);
            $.ajax({
                type: 'get',
                url: 'GetData.ashx?t=' + Rand,
                data: "codes=" + codes,
                success: function (json) {
                    removeRows();
                    callback(json);
                }
            });
        }
        function codeIsRight(code) {
            if (code == undefined) {
                code = document.getElementById("sfundcode").value;
            }
            var Rand = Math.random();
            $.ajax({
                type: 'get',
                url: 'GetData.ashx?g=' + Rand,
                data: "ensure=" + code,
                success: function (json) {
                    if (json == "1") {//代码正确
                        doAddFavFund();
                    } else {//代码错误
                        $("#errmessage").html("暂无符合条件的基金，请重新输入");
                        initFavList();
                    }
                }
            });
        }
        function callback(msg) {
            if (msg == "") {
                var str = "<tr height=\"200\"><td align=\"center\" valign=\"top\" colspan=\"10\" style=\"background-color: White\"><br /><br /><span style=\"font-size: 35px; color: #003399;\">您还没有自选基金，请于上方进行添加。</span></td></tr>";

                $("#datatable").append(str);
            } else {

                $("#datatable").append(msg);
            }


        }

        function setcookie(name, value) {
            var the_date = new Date("December 31, 2060");
            var expiresDate = the_date.toGMTString();
            //document.cookie = "fundfavlist=" + value + ";expires=" + expiresDate;
            document.cookie = "fundfavlist=" + value + ";expires=" + expiresDate + ";path=/;domain=fund.stockstar.com";
        }

        function delcookie(value) {
            if (confirm("确认删除？")) {
                var oldcookie = getcookie("fundfavlist");
                var newcookie = "";
                var mycookies = oldcookie.split("_");
                for (var i = 0; i < mycookies.length; i++) {
                    if (mycookies[i] != value && mycookies[i] != "") {
                        newcookie += mycookies[i] + "_";
                    }
                }
                setcookie("fundfavlist", newcookie);
                initFavList();
            }
        }

        function getcookie(name) {
            var cookieStr = document.cookie; //取 cookie 字符串，由于 expires 不可读，所以 expires 将不会出现在 cookieStr 中。

            if (cookieStr == "") {
                return ""; //没有取到 cookie 字符串，返回默认值
            }
            var cookieValue = cookieStr.split(";"); //将各个 cookie 分隔开，并存为数组，多个 cookie 之间用分号加空隔隔开，不过前面我们只使用了一个 cookie，它的值与 expires 之间也是用分号加空格隔开的
            var varName = name;
            var startPos = -1;
            var endPos = -1;
            for (var i = 0; i < cookieValue.length; i++) {
                startPos = cookieValue[i].indexOf(varName);
                if (startPos == -1) {
                    continue; //当前 cookie 不是名称为 varName 的 cookie，判断下一个 cookie
                }
                startPos += varName.length + 1; //当前 cookie 就是名称为 varName 的 cookie，由于有等号，所以 +1
                endPos = cookieValue[i].length;
                var css = (cookieValue[i].substring(startPos, endPos));
                return css;
            }

            return "";
        }

        function removeRows() {
            $("#datatable tr").each(function () {
                //alert($(this).attr("id"));
                if ($(this).attr("id") != "row1") {
                    $(this).remove();
                }
            });
        }
    </script>
    <div class="search_top">
        <%-- <form action="" method="post" id="frmSerachCode" style="position: relative; z-index: 99;" target="_self">--%>
        <span>添加自选基金：</span>
        <input name="ajaxinputFav" id="sfundcode" type="text" class="text" style="color: Gray;"
            value="代码/名称/拼音" onmousedown="changeIdFav(this,'RTQuote','floattable');" onclick="if (this.value =='代码/名称/拼音'||this.value =='请输入关键字') this.value='';"
            autocomplete="off" />
        <input type="button" class="addFavFunds" value="添加" onclick="codeIsRight();" />
        <input type="hidden" id="target" name="targetFav" value="RTQuote" />
        <div id="ajaxdivFav" class="floattable" style="margin-left: 128px">
        </div>
        <span class="favMessage" id="errmessage"></span>
        <%-- </form>--%>
        <script src="http://fund.stockstar.com/funds/js/fundMangFav.js" type="text/javascript"
            charset="gb2312"></script>
    </div>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="searchBar" runat="Server">
    <script type="text/javascript" language="javascript">
        function doAddFavFund() {

            //loading();

            var codestr = document.getElementById("sfundcode").value;

            if (codestr == '代码/名称/拼音') {
                codestr = '';
            }
            if (codestr == '') {
                codestr = getRequestCode();
            }
            if (codestr == '') {
                alert("请输入要查询的代码！");
                return;
            }
            var oldcookie = getcookie("fundfavlist");
            if (oldcookie == undefined) {
                oldcookie = "";
            }
            var isExist = false;
            if (oldcookie.indexOf(codestr + "_") >= 0) {
                $("#errmessage").html("所选基金已存在");
                isExist = true;
            }
            var codes = oldcookie.split("_");
            var allcount = 0;
            for (var i = 0; i < codes.length; i++) {
                if (codes[i] != "") {
                    allcount++;
                }
            }
            var over20 = false;
            if (allcount >= 20) {
                $("#errmessage").html("对不起，您只能保存20条自选基金。");
                over20 = true;
            }
            //
            var newcookie = oldcookie + codestr + "_"; ;
            if (!isExist && !over20) {
                setcookie("fundfavlist", newcookie);
            }
            initFavList();
        }
    
    </script>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="mainTb" runat="Server">
    <div style="width: 960px; margin: 0 auto;">
        <table width="100%" border="0" cellpadding="0" align="center" cellspacing="1" bgcolor="#dfe0e1"
            id="datatable">
            <tr align="center" bgcolor="#e2f0fe" style="line-height: 25px;" id="row1">
                <td height="25">
                    <span style="color: #000;">序号</span>
                </td>
                <td height="25">
                    代码
                </td>
                <td>
                    简称
                </td>
                <td>
                    净值日期
                </td>
                <td style="padding: 5px 0 5px 0;">
                    最新净值
                </td>
                <td>
                    累计净值
                </td>
                <td>
                    变动率%
                </td>
                <td>
                    <span style="color: #000;">基金类型</span>
                </td>
                <td>
                    <span style="color: #000;">相关功能</span>
                </td>
                <td>
                    <span style="color: #000;">操作</span>
                </td>
            </tr>
            <%--            <tr height="200">
                <td align="center" valign="top" colspan="10" style="background-color: White">
                    <br />
                    <br />
                    <span style="font-size: 35px; color: #003399;">您还没有自选基金，请于上方进行添加。</span>
                </td>
            </tr>--%>
        </table>
        <p style="text-align: left; line-height: 30px;">
            注：如果是货币基金，最新净值、累计净值分别表示每万份基金单位收益和七日年化收益率(%)。</p>
    </div>
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="nav" runat="server">
    自选基金
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="headtitle" runat="Server">
    <title>基金首页-自选基金</title>
</asp:Content>
